﻿/// <reference path="jquery-1.5.1.min.js" />

/*
<div id="addComment" class="modal hide">
    <div class="modal-header">
        <a href="#" class="close">&times;</a>
        <h3>
            Task Manager</h3>
    </div>
    <div class="modal-body">
        <div class="input">
            <textarea class="xxlarge" name="textarea" id="text" rows="3"></textarea>        
        </div> 
    </div>
    <div class="modal-footer">
        <input type="button" class="btn primary" id="dialogId-btn1" value="OK">
        <input type="button" class="btn secondary" id="dialogId-btn2" value="Cancel">
    </div>
</div>
*/

// onOkClick handler should look like
// function(text) {
//   some code here
// }

// ASSUMPTION: Ok and Cancel buttons MUST BE named as '<dialogname>-btn1' and '<dialogname>-btn2'

function InputTextDialog(dialogId, caption, onOkClick) {
    var dialogRef = '#' + dialogId;
    $(dialogRef + '> .modal-header > h3').text(caption);

    var selectBtn = dialogRef + '> .modal-footer > #';
    var selectBtn1 = selectBtn + dialogId + "-btn1";
    var selectBtn2 = selectBtn + dialogId + "-btn2";

    var modalResult;
    $(selectBtn1).click(function () {
        var text = $(dialogRef + ' > .modal-body textarea').val()
        $(dialogRef).modal('hide');
        onOkClick(text);
    });
    $(selectBtn2).click(function () {
        $(dialogRef).modal('hide');
    });

    $(dialogRef).modal({ show: true, backdrop: 'static', keyboard: true });

    return modalResult;
}